package cn.wolfcode.tieba.service.impl;

import cn.wolfcode.tieba.domain.Tiezi;
import cn.wolfcode.tieba.mapper.TieziMapper;
import cn.wolfcode.tieba.mapper.UserMapper;
import cn.wolfcode.tieba.service.ITieziService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 王金龙
 * @date 2021/2/6 19:35
 */
@Service
public class TieziServiceImpl extends ServiceImpl<TieziMapper, Tiezi> implements ITieziService {
    @Autowired
    private TieziMapper tieziMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<Tiezi> listAll() {
        List<Tiezi> tiezis = tieziMapper.selectList(new QueryWrapper<>());
        for (Tiezi tiezi : tiezis) {
            tiezi.setAuthor(userMapper.selectById(tiezi.getAuthorId()));
            tiezi.setReplyUser(userMapper.selectById(tiezi.getLastReplyId()));
        }
        return tiezis;
    }
}
